All Questions
Tagged with phpdesign-patterns
118 questions
3votes
1answer
326views
Applying the Strategy pattern for payment methods
The strategy pattern is applied in the code below in the payment separation solution. Please evaluate if it is well done according to standards. I would be very grateful for suggestions. ...
3votes
1answer
134views
Scrape multiple twitch IRC chats
I've always struggled to create and sustainable, organizated, clean code. I tried to use a Factory method and it's working better now that I created another class. I know I should write documentation,...
6votes
2answers
503views
Usage of Factory pattern for maintaing bookshelf having books, magazine and notes
I have tried to achieve the following task using Factory Pattern with PHP version 7.0. Define the classes and their methods (including parameters and return types) for a system that consist of a ...
2votes
1answer
79views
Transform Data from JSON and CSV to another JSON format
I have 2 files wholesaler_a.csv ...
0votes
1answer
86views
Learning factory design pattern [closed]
I'm making the very common example of Factory design pattern which creates a factory of cars and return an instance of a car. I found a example here https://refactoring.guru/design-patterns/factory-...
6votes
1answer
395views
Return payload in service layer
In my project I am using the ADR architecture, a branch of MVC. In my actions (Controllers) I handle only data that comes from the request. When there is a business rule that defines which status code ...
3votes
2answers
95views
PHP Status class : pattern or anti-pattern
I want to abstract some code which does a bunch of checks and returns a boolean - since I am using the business logic in several places. But I also want to get back the reason why, if it was returned ...
1vote
1answer
66views
Chain of responsibility and handlers dependent on each other
I'm importing data from file to many tables in database. It may look like this: First Name, Last Name, Meeting John, Doe, 2020-04-24 08:00:00 Some fields like "...
2votes
0answers
99views
router system like laravel, how to manage routes creation and router handler?
i'm trying to create a url router system, for educational purposes, that has a similar usage like Laravel has, but i'm curious about how i can register the routes like laravel does (with single calls ...
2votes
0answers
92views
implementation of a mvc url router with low coupling and solid principles
i'm building an url router and i want to improve it to respect SOLID principles, i want suggestions of how can i make it less coupled. here's my current code: Router.php ...
0votes
1answer
45views
Refactor the method which is the sequence of the similarly looking steps to (or towards) the design patterm(s) [closed]
I need some help to understand if the code below could be refactored to something less straightforward, less repetitive and more towards any appropriate pattern. What I feel uncomfortable with in ...
1vote
1answer
793views
Laravel 5.8: prevent duplicated code
Sometimes we have this code blocks that is repeated in the same controller again and again, I reviewed the Repository Pattern but I didn't understand how to deal with some kind of these duplication. ...
3votes
2answers
82views
Organise method flow
I have something like a shop. It is limited to a checkout page, which will send an email. Nothing big, but a nice thing to learn more OOP. Almost every time I develop new classes I am wondering how ...
4votes
1answer
287views
strategy pattern, good practices on how to switch between classes
i'm using an external API that posts products and orders into a marketplace, and it provides a class that in each request i have to specify an endpoint, ...
4votes
1answer
128views
Enables markup to instantiate objects, call methods, and generate HTML
I created this package PXP. PXP enables markup to instantiate objects, call methods, and generate HTML. It works similar to a server-side templating engine, but rather than enforcing braces it ...